import java.util.ArrayList;

/** An action currently has a name and string and array of triggers. 
 * 
 * @author MegaTool
 *
 */
/**
 * @author MegaTool
 *
 */
public class Action {
	
	/** The name of the Action */
	private String name;
	/** The description of the Action */
	private String description;
	
	private boolean loaded;
	/** the list of triggers that can set off this action */
	private ArrayList<ActionTrigger> triggerList;
	
	/** the main constructor */
	public Action(){
		triggerList = new ArrayList<ActionTrigger>();
		name = "";
		description = "";
		setLoaded(false);
	}
	/** adds a trigger to this actions trigger list
	 * @param trigger is the ActionTrigger to add to the list  */
	public void addTrigger(ActionTrigger trigger){
		triggerList.add(trigger);
	}
	
	/** gets a trigger from the array list
	 * 
	 * @param index the index of the trigger that is to be retrieved 
	 * @return
	 */
	public ActionTrigger getTrigger(int index){
		return triggerList.get(index);
	}
	
	/** Checks this Action's ArrayList of ActionTriggers to see if it contains the passed ActionTriger
	 * 
	 * @param trigger The ActionTrigger to be searched for within this Action's ArrayList of ActionTriggers
	 * @return finding the passed trigger returns true, effectively meaning the action has been triggered. 
	 */
	public boolean containsTrigger(ActionTrigger trigger){
		boolean hasTrigger = false;
		for(int i=0;i<triggerList.size();i++){
			if(triggerList.get(i).y == trigger.y && 
					triggerList.get(i).x == trigger.x &&
							triggerList.get(i).getFacing() == trigger.getFacing()){
				hasTrigger = true;
			}//end if
		}//end for
		return hasTrigger; // True means Action has been Triggered; False means it has not
	}//end containsTrigger();

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public void setName(String name) {
		this.name = name;
		
	}

	public void setDescription(String description) {
		this.description = description;
		
	}

	/**
	 * @return the loaded
	 */
	public boolean isLoaded() {
		return loaded;
	}

	/**
	 * @param loaded the loaded to set
	 */
	public void setLoaded(boolean loaded) {
		this.loaded = loaded;
	}

	public int getTriggerArraySize() {
		
		return triggerList.size();
	}

	

}
